Smallest chosen word - HackerEarth Solution


Greedy

Python Code:

c = input()
x = input()
x = x.split(' ')
y = []
if len(x)==1:
    print(x[0], end = '')
    print(3, end = '')
elif len(x)==2:
    print(x[0], end = '')
    print(3, end = '')
else:
    print(x[0], end = '')
    for i in range(len(x[1])-1):
        if x[1][i]<=x[1][i+1] and x[1][i]!=x[2][i]:
            y.append(x[1][i])
        else:
            continue
    print(''.join(y), end = '')
    print(x[2])


Comments

Submit
0 Comments
More Questions

Partitioning binary strings
Special sets
Smallest chosen word
Going to office
Color the boxes
Missing numbers
Maximum sum
13 Reasons Why
Friend's Relationship
Health of a person
Divisibility
A. Movement
Numbers in a matrix
Sequences
Split houses
Divisible
Three primes
Coprimes
Cost of balloons
One String No Trouble
Help Jarvis!
Lift queries
Goki and his breakup
Ali and Helping innocent people
Book of Potion making
Duration
Birthday Party
e-maze-in
Bricks Game
Char Sum